package activitys;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Handler;
import android.os.Message;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.view.Window;

import java.io.File;

import mytool.MyDialog;
import mytool.PrintLog;
import tool.ducong.com.mygpsdemo.GPS_TOOL;
import tool.ducong.com.mygpsdemo.MyAPP;
import tool.ducong.com.mygpsdemo.R;


public class MainActivity extends Activity {
   public static GPS_TOOL gps_tool;

    private Handler hander = new Handler() {
        @Override
        public void handleMessage(Message msg) {
          switch (msg.what){
              case 0:
                  MyAPP.activityflag=2;
                  startActivity(new Intent(MainActivity.this, Base_stationActivity.class));
                  break;
              case 1:
                  break;
              default:break;

          }

        }
    };

    private Runnable runnable = new Runnable() {
        @Override
        public void run() {
            if (gps_tool != null && !gps_tool.checkGPS()) {
                hander.postDelayed(runnable, 2000);
            }

        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_main);

        //GPS类

                if (gps_tool == null) {
                    PrintLog.i("MYGPSDEMO=创建");
                    gps_tool = new GPS_TOOL(MainActivity.this, R.id.myGPS);
                }
                gps_tool.openGPSSettings();


//      GPS Activity界面
//      startActivity(new Intent(MainActivity.this,GpsActivity.class));
//      this.finish();

    }

    @Override
    protected void onStart() {
        MyAPP.activityflag=0;
        super.onStart();
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == 0 && gps_tool != null) {
            PrintLog.i("MYGPSDEMO=回调");
            if (!gps_tool.checkGPS()) {
                hander.postDelayed(runnable, 2000);
            }
        }
    }


    public void base_station(View v) {
        MyDialog.inputPassword(this,hander);
    }

    public void mobile(View v) {

        MyAPP.activityflag=1;
        startActivity(new Intent(MainActivity.this, MobileActivity.class));
    }
    public void setTing(View v) {
        MyAPP.activityflag=3;
        startActivity(new Intent(MainActivity.this, SetTing.class));
    }

    @Override
    protected void onDestroy() {
        gps_tool.onActivityDestroy();
        super.onDestroy();
    }
}
